import Koa from "koa";

interface failInfo {
    code: number,
    data: any,
    msg: string
}

export const response = () => {
    return async (ctx: Koa.Context, next: Koa.Next) => {
        console.log("执行了挂载操作------------------")
        ctx.res.fail = (code: number = 0, data: any = null, msg: string = "fail") => {
            ctx.body = {
                code,
                result: data,
                msg,
            };
        };

        ctx.res.success = (code: number) => {
            ctx.body = {
                code: code ?? 0,
                result: ctx.body,
                msg: ctx.msg || 'success',
            };
        };
        await next();
    };
};

